/**********************************************************
 * File description:dyelibrary.cpp
 * Function:染料库管理类
 * Current Version: 1.0.0
 * Author: 王伟豪
 * Date: 2022-10-02
 *  -----
 *  Copyright by BoKun Software.
 **********************************************************/
#include "DyelibraryService.h"



DyeLibrary::DyeLibrary()
{
    path = QCoreApplication::applicationDirPath();
    sqlD = new SqliteDriver();
    sqlD->setDBDir(path);
    sqlD->openDB(DBNAME);
}

DyeLibrary::~DyeLibrary()
{
    sqlD->closeDB();
}



/*!
 * \brief 向CHROMOSOME中插入数据
 *
 * \param QString name, QString waveLength,
 * \param QString creator, QString type
 *
 * Detail here!!!
 */
void DyeLibrary::create(QString name, QString waveLength, QString creator, QString type,QString status)
{

    QHash<QString,QString> data;
    data["name"] = name;
    data["wave_length"] = waveLength;
    data["creator"] = creator;
    data["type"] = type;
    data["status"] = status;
    sqlD->addData(CHROMOSOME,data); //插入操作
}




/*!
 * \brief 删除CHROMOSOME中某一条数据
 *
 * \param QString id   要删除数据的id号
 *
 * Detail here!!!
 */
void DyeLibrary::remove(QString id)
{
    sqlD->delData(CHROMOSOME,"where id = "+id); //删除操作
}



/*!
 * \brief 修改CHROMOSOME中某一条数据
 *
 * \param QString id,  要修改的数据的id
 * \param QString name, QString waveLength,
 * \param QString creator, QString type
 *
 * Detail here!!!
 */
void DyeLibrary::revise(QString id,QString name, QString waveLength, QString creator, QString type,QString status)
{

    QHash<QString,QString> data;
    data["name"] = name;
    data["wave_length"] = waveLength;
    data["creator"] = creator;
    data["type"] = type;
    data["status"] = status;
    data["update_time"] = "DATETIME('now','localtime')";
    sqlD->updateData(CHROMOSOME,data,"where id = "+id);
}




/*!
 * \brief 用于获取CHROMOSOME中的全部数据
 *
 * \return QList<QHash<QString,QString>> 由qlist封装每一条数据（qhash）
 *
 * Detail here!!!
 */
QList<QHash<QString,QString>> DyeLibrary::show()
{
    QList<QHash<QString,QString>> data;
    sqlD->queryExec("SELECT * FROM chromosome ORDER BY id",data);
    return data;
}


